/*
 *  Copyright 2011 yura.
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *  under the License.
 */
package org.opu.db_vdumper.ui.component.tabel.views;

import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Point;
import javax.swing.JComponent;

/**
 *
 * @author Potochnak Yana
 */
public abstract class PikeView extends JComponent{
    public static int TOP_DIRECTION = 270;
    public static int RIGHT_DIRECTION = 180;
    public static int BELOW_DIRECTION = 90;
    public static int LEFT_DIRECTION = 0;

    protected int direction;
    protected Image imageBorder;

    @Override
    protected  void paintComponent(Graphics g) {
        super.paintComponent(g);
        draw( (Graphics2D) g, locate());//new Point(s.width, s.height));
    }

    /**
     *  Draw pike on specific graphic enviroment.
     * @param g2 specific graphic enviroment where will be drawing
     * @param pos where from start to draw
     */
    public abstract void draw(Graphics2D g2, Point pos);

    /**
     *  Return all points in curent Picke, except top point
     * @return all points in curent Picke
     */
    public abstract Point[] points();

    public Point locate() {
        Dimension s = getPreferredSize();

        if (direction == TOP_DIRECTION) {
            return new Point(s.width / 2, 0);
        } else if (direction == BELOW_DIRECTION) {
            return new Point(s.width / 2, s.height);
        } else if (direction == LEFT_DIRECTION) {
            return new Point(0, s.height / 2);
        } else {
            return new Point(s.width, s.height / 2);
        }
    }

    public int getDirection() {
        return direction;
    }

    public void setDirection(int direction) {
        this.direction = direction;
    }

    public Image getImageBorder() {
        return imageBorder;
    }

    public void setImageBorder(Image imageBorder) {
        this.imageBorder = imageBorder;
    }

}
